package de.game.actor.creep.spawn;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import de.core.gameplay.actor.AbstractActor;
import de.core.utils.ImageUtils;
import de.game.actor.creep.TestCreep;

public class Spawn extends AbstractActor {
    private final long timeBetweenSpawns = 5000;
    private long lastSpawnTime;

    public Spawn() {
        super(createImage(), 30, 400);
    }

    private static BufferedImage createImage() {
        BufferedImage image = ImageUtils.createCompatibleImage(8, 64);
        Graphics graphics = image.getGraphics();
        graphics.setColor(new Color(255, 140, 255));
        graphics.fillRect(0, 0, 8, 64);
        graphics.dispose();
        return image;
    }

    @Override
    protected void act() {
        if (System.currentTimeMillis() > lastSpawnTime + timeBetweenSpawns) {
            getLevel().addActor(new TestCreep((int) getLocation().getX(), (int) getLocation().getY()));
            lastSpawnTime = System.currentTimeMillis();
        }
    }

}
